package cn.wenzy.aurora.framework.support.validation.bean;


import cn.hutool.core.util.StrUtil;
import cn.wenzy.aurora.framework.constant.IConstant;

import java.util.ArrayList;
import java.util.List;

public class ValidationMessage implements IConstant {

    private Boolean validate;

    private List<String> message;

    private ValidationMessage(){
        this.validate = true;
        this.message = new ArrayList<>();
    }

    private ValidationMessage(boolean validate, String message){
        this();
        this.validate(validate, message);
    }

    public static ValidationMessage of(boolean validate) {
        return new ValidationMessage(validate, null);
    }

    public static ValidationMessage of(boolean validate, String message) {
        return new ValidationMessage(validate, message);
    }

    public boolean isValidate() {
        return validate;
    }

    public void validate(boolean validate, String message) {
        this.validate = this.validate && validate;
        if (StrUtil.isNotBlank(message)) {
            this.message.add(message);
        }
    }

    public void validate(ValidationMessage message) {
        this.validate = this.validate && message.isValidate();
        this.message.addAll(message.message);
    }

    public String message() {
        return String.join(SEMICOLON, message);
    }

}
